// Tags: Multi Backpack
#include <algorithm>
#include <cctype>
#include <cstdio>

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

const int N = 1e4 + 5;
int n, m, c;
int q[N], f[N], dp[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P1782 旅行商的背包.in", "r", stdin);
  freopen("P1782 旅行商的背包.out", "w", stdout);
#endif
#endif

  read(n), read(m), read(c);
  for (int i = 1, v, w, d; i <= n; i++) {
    read(v), read(w), read(d);
    for (int j = 0; j < v; ++j) {
      for (int h = 1, t = 0, k = 0; k * v + j <= c; k++) {
        int x = dp[k * v + j] - k * w;
        while (h <= t && x > f[t]) t--;
        q[++t] = k;
        f[t] = x;
        if (h <= t && q[h] + d < k) h++;
        dp[k * v + j] = f[h] + k * w;
      }
    }
  }
  for (int i = 0, a, b, d; i < m; i++) {
    read(a), read(b), read(d);
    for (int j = c; j >= 0; --j)
      for (int k = 0; k <= j; ++k)
        if (dp[j - k] + (a * k + b) * k + d > dp[j])
          dp[j] = dp[j - k] + (a * k + b) * k + d;
  }
  printf("%d", dp[c]);
  return 0;
}